package com.hw.one.collect.zj.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Copyright 2017 汉威.智慧环保事业部.
 * Created by 李亚坤 on 2017/05/16 14:52.
 */
public class ZjConfig {

    private static Properties properties = new Properties();

    private static ZjConfig zjConfig;


    /**
     * 获取认证实例
     * @return
     */
    public static ZjConfig getInstance(){
        if(null == zjConfig){
            zjConfig = new ZjConfig();
            initConfig();
        }
        return zjConfig;

    }
    /**
     * 初始化认证信息
     */
    private static void initConfig(){
        initDefault();
    }

    private static void initDefault(){
        String defaultSrc = "/config/zjfivemin.properties";
        InputStream is = ZjConfig.class.getResourceAsStream(defaultSrc);
        try {
            if(is != null){
                properties.load(is);
            }
        } catch (IOException e) {

        }finally {
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 通过key获取value
     * @return
     */
    public static String get(String key){
        if (null == zjConfig) {
            zjConfig = new ZjConfig();
            initConfig();
        }
        String value = properties.getProperty(key);
        return value;
    }
}
